package com.lesson00;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestActionTwo {
    public static void main(String[] args) {
        //两个按钮实现同一个监听
        Frame frame = new Frame("开始-结束");
        Button button1 = new Button("start");
        Button button2 = new Button("stop");

        //定义触发返回的命令
//        button2.setActionCommand("button2-stop");
//        button1.setActionCommand("button1-start");

        MyMontior myMontior = new MyMontior();
        button2.addActionListener(myMontior);
        button1.addActionListener(myMontior);
        frame.add(button1,BorderLayout.NORTH);
        frame.add(button2,BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }
}
class MyMontior implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("按钮被点击了"+e.getActionCommand());
    }

}